import time

import pytest
from common.request_util_test import RequestUtil
from common.test_yaml_util_test import YamlUtil
from config import datas


class TestMultiClusterManagement:

    @pytest.mark.parametrize('clusterinfo', YamlUtil().read_testcase_yaml('v24.09/multiclusterManagement/1_get_cluster_list.yaml'))
    def test_get_cluster_list(self, clusterinfo, get_env_info):
        # 获取集群列表接口
        baseUrl = get_env_info
        url = baseUrl + clusterinfo['request']['url']
        method = clusterinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        # print(req.content)
        assert req.status_code == clusterinfo['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('clusterinfo', YamlUtil().read_testcase_yaml('v24.09/multiclusterManagement/2_add_cluster.yaml'))
    def test_add_cluster(self, clusterinfo, get_env_info):
        # 纳管集群接口
        baseUrl = get_env_info
        url = baseUrl + clusterinfo['request']['url']
        method = clusterinfo['request']['method']
        header = clusterinfo['request']['header']
        if '空' not in clusterinfo['name']:
            clusterinfo['request']['data']['kubeconfig'] = datas.kubeconfig
        data = clusterinfo['request']['data']
        req = RequestUtil().send_request(method, url,headers= header,json=data)
        time.sleep(10)
        # print(req.content)
        assert req.status_code == clusterinfo['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('clusterinfo', YamlUtil().read_testcase_yaml('v24.09/multiclusterManagement/3_modify_cluster.yaml'))
    def test_modify_cluster(self, clusterinfo, get_env_info):
        # 修改集群标签接口
        baseUrl = get_env_info
        url = baseUrl + clusterinfo['request']['url']
        method = clusterinfo['request']['method']
        header = clusterinfo['request']['header']
        data = clusterinfo['request']['data']
        req = RequestUtil().send_request(method, url,headers= header,json=data)
        # print(req.content)
        assert req.status_code == clusterinfo['validate'][0]['equals']['status_code']

    @pytest.mark.parametrize('clusterinfo', YamlUtil().read_testcase_yaml('v24.09/multiclusterManagement/4_delete_cluster.yaml'))
    def test_delete_cluster(self, clusterinfo, get_env_info):
        # 解除集群纳管接口
        baseUrl = get_env_info
        url = baseUrl + clusterinfo['request']['url']
        method = clusterinfo['request']['method']
        req = RequestUtil().send_request(method, url)
        # print(req.content)
        assert req.status_code == clusterinfo['validate'][0]['equals']['status_code']